package api

import (
	"net/http"

	"github.com/gin-gonic/gin"
)

type RenderHtmlAPI struct {
}

func (api *RenderHtmlAPI) SingleString(ctx *gin.Context) {
	ctx.HTML(http.StatusOK, "singlestring/index.html", "张三")
}

type User struct {
	Name string
	Age  int
}

func (api *RenderHtmlAPI) SingleStruct(ctx *gin.Context) {
	ctx.HTML(http.StatusOK, "singlestruct/index.html", &User{"张三", 18})
}

func (api *RenderHtmlAPI) BaseArraySlice(ctx *gin.Context) {
	ctx.HTML(http.StatusOK, "basearrayslice/index.html", []string{"张三", "李四", "王五"})
}

func (api *RenderHtmlAPI) StructArraySlice(ctx *gin.Context) {
	users := []User{}
	users = append(users, User{"张三", 18})
	users = append(users, User{"李四", 19})
	users = append(users, User{"王五", 20})
	ctx.HTML(http.StatusOK, "structarrayslice/index.html", users)
}

func (api *RenderHtmlAPI) Map(ctx *gin.Context) {
	ctx.HTML(http.StatusOK, "singlestruct/index.html", gin.H{
		"Name": "张三",
		"Age":  18,
	})
}

func (api *RenderHtmlAPI) MultiStruct(ctx *gin.Context) {
	ctx.HTML(http.StatusOK, "multistruct/index.html", gin.H{
		"zhangsan": &User{"张三", 18},
		"lisi":     &User{"李四", 19},
	})
}
